﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.Manager;
using Direct.IDAL.Manager;
using DirectSell.Common.Session;

namespace DirectSell.BLL.Manager.Login
{
    /// <summary>
    /// 管理员登录
    /// </summary>
    public class ManagerLoginService:ManagerService
    {

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        protected IManagerLoginRepository _repository { get; set; }
        public ManagerLoginService(IManagerLoginRepository repository)
        {
            this._repository = repository;
        }
        #endregion

        #region 操作入口
        /// <summary>
        /// 操作入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected override ManagerRespCode Operation<T>(T param)
        {
            var model = param as LoginReq;

            if (model == null)
            {
                return ManagerRespCode.传入参数不正确;
            }

            if (!_repository.CheckManager(model.ManagerCode, model.ManagerPassword))
            {
                return ManagerRespCode.验证失败;
            }

            var info = _repository.QueryManagerInfo(model.ManagerCode);

            //写入Session
            ManagerSessionModel sessionModel = new ManagerSessionModel()
            {
                ManagerCode = info.ManagerCode,
                ManagerName = info.ManagerName,
                Role = info.Role
            };

            SessionInfo.SetManagerSession(sessionModel);

            return ManagerRespCode.成功;

        }
        #endregion
    }
}
